import AdAdapter from "./AdAdapter";
import RecorderAdapter from "./RecorderAdapter";
export default class SDKAdatper {
    protected _name: string;
    protected _sdk: any

    constructor(sdk: any, name: string) {
        this._sdk = sdk;
        this._name = name;
    }

    getName() {
        return this._name;
    }

    hasSDK() {
        return this._sdk != undefined;
    }


    showImage(_tempFilePath: string) {
        this._sdk.previewImage(_tempFilePath)
    }

    hasLogin() {
        return this.hasSDK() && this._sdk.login != undefined;
    }

    hasPreviewImage() {
        return this.hasSDK() && this._sdk.previewImage != undefined
    }

    createImage(canvas: any, texture?: any): any {
        console.log(' createImage ')
        // let canvas = this.getCanvas()
        let data = {
            x: 0,
            y: 0,
            width: canvas.width,
            height: canvas.height,
            // destination file sizes
            destWidth: canvas.width,
            destHeight: canvas.height,
            fileType: 'png',
            quality: 1
        }
        return data;
    }

    getFilePath(canvas: any, data: any) {
        let _tempFilePath = canvas.toTempFilePathSync(data);
        return _tempFilePath
    }

    saveFile(_tempFilePath: string, show: boolean, call: (r: number) => void) {
        if (!this.hasSDK()) {
            return;
        }
        this._sdk.saveImageToPhotosAlbum({
            filePath: _tempFilePath,
            success: (res: any) => {
                console.log(`Capture file success!${_tempFilePath}`, res);
                // self.label = '图片加载完成，等待本地预览';

                if (show) {
                    this.showImage(_tempFilePath)
                }
                if (call) {
                    call(1)
                }
            },
            fail: () => {
                if (call) {
                    call(0)
                }
            }
        })

    }

    hasBannerAd() {
        if (!this.hasSDK()) {
            return false;
        }
        if (!this._sdk.createBannerAd) {
            return false;
        }
        return true;
    }
    createBannerAd(obj: any) {
        if (!this.hasBannerAd()) {
            return null;
        }
        return new AdAdapter(this._sdk.createBannerAd(obj))
    }


    getDataPath() {
        if (!this.hasSDK()) {
            return ''
        }

        if (this._sdk['env']) {
            return this._sdk['env'].USER_DATA_PATH
        } else {
            return ''
        }

    }

    hasShare() {
        if (!this.hasSDK()) {
            return false;
        }
        return this._sdk.getShareInfo != undefined;
    }

    loadSubpackage(obj: object) {
        if (this._sdk && this._sdk.loadSubpackage) {
            return this._sdk.loadSubpackage(obj)
        }
        return null
    }

    getFileSystemManager() {


        if (this._sdk && this._sdk.getFileSystemManager)
            return this._sdk.getFileSystemManager();
        else
            return null;

    }

    hasBlockAd() {
        return this.hasSDK() && this._sdk.createBlockAd != undefined;
    }

    createBlockAd(obj: any) {
        if (this.hasBlockAd()) {
            return new AdAdapter(this._sdk.createBlockAd(obj))
        }
        return null;
    }

    hasAppBox() {
        return this.hasSDK() && this._sdk.createAppBox
    }

    createAppBox(obj: any) {
        if (this.hasAppBox()) {
            return new AdAdapter(this._sdk.createAppBox(obj))
        }
        return null;
    }

    createGamePortalAd(obj: any) {
        if (this.hasSDK() && this._sdk.createGamePortalAd) {
            return new AdAdapter(this._sdk.createGamePortalAd(obj))
        }
        return null;
    }

    vibrateShort(obj?: any) {
        if (this.hasSDK() && this._sdk.vibrateShort) {
            this._sdk.vibrateShort(obj)
        }
    }

    showToast(obj: any) {
        if (this._sdk && this._sdk.showToast) {
            this._sdk.showToast(obj)
        }
    }

    getSystemInfoSync() {
        if (!this.hasSDK() || !this._sdk.getSystemInfoSync) {
            return null;
        }
        return this._sdk.getSystemInfoSync()
    }

    hasInsertAd() {
        if (!this.hasSDK()) {
            return false
        }
        return this._sdk.createInterstitialAd
    }

    createInterstitialAd(obj: any) {
        if (!this.hasSDK()) {
            return null;
        }
        return new AdAdapter(this._sdk.createInterstitialAd(obj))

    }

    hasRewardedVideoAd() {
        if (!this.hasSDK() || !this._sdk.createRewardedVideoAd) {
            return false;
        }
        return true;
    }

    createRewardedVideoAd(obj: any) {
        if (!this.hasSDK() || !this._sdk.createRewardedVideoAd) {
            return null;
        }

        return new AdAdapter(this._sdk.createRewardedVideoAd(obj))

    }

    onHide(func: Function) {
        if (this.hasSDK() && this._sdk.onHide) {
            this._sdk.onHide(func)
        }
    }

    onShow(func: Function) {
        if (this.hasSDK() && this._sdk.onShow) {
            this._sdk.onShow(func)
        }
    }

    hasNativeAd() {

        return false
    }
    createNativeAd(obj: any): AdAdapter {
        return null;
    }


    getShareInfo(obj: any) {
        if (this.hasSDK() && this._sdk.getShareInfo) {
            this._sdk.getShareInfo(obj)
        }
    }

    onShareAppMessage(func: Function) {
        if (this.hasSDK() && this._sdk.onShareAppMessage) {
            this._sdk.onShareAppMessage(func)
        }
    }

    showShareMenu(obj: any) {
        if (this.hasSDK() && this._sdk.showShareMenu) {
            this._sdk.showShareMenu(obj)
        }
    }

    updateShareMenu(obj: any) {
        if (this.hasSDK() && this._sdk.updateShareMenu) {
            this._sdk.updateShareMenu(obj)
        }
    }

    shareAppMessage(obj: any) {
        if (this.hasSDK() && this._sdk.shareAppMessage) {
            this._sdk.shareAppMessage(obj)
        }
    }

    navigateToMiniProgram(obj: any) {
        if (this.hasSDK()) {
            if (this._sdk.navigateToMiniProgram) {
                this._sdk.navigateToMiniProgram(obj)
            }
        }
    }

    hasRecorder() {
        return false
    }

    getGameRecorderManager(): RecorderAdapter {
        return null;
    }

    checkSession(obj: any) {
        if (this.hasSDK() && this._sdk.checkSession) {
            this._sdk.checkSession(obj)
        }
    }

    login(obj: any) {
        if (this.hasSDK() && this._sdk.login) {
            this._sdk.login(obj)
        }
    }

    getUserInfo(obj: any) {
        if (this.hasSDK() && this._sdk.getUserInfo) {
            this._sdk.getUserInfo(obj)
        }
    }

    hasShortcutInstalled(obj: any) {
        return false
    }


    installShortcut(obj: any) {

    }


    showModal(obj: any) {
        if (this.hasSDK() && this._sdk.showModal) {
            this._sdk.showModal(obj)
        }
    }

    createMoreGamesButton(obj: any): any {
        return null;
    }

    showMoreGamesModal(obj: any) {

    }

    getOpenDataContext() {
        if (this.hasSDK() && this._sdk.getOpenDataContext) {
            return this._sdk.getOpenDataContext()
        }
        return null;
    }

    getUpdateManager() {
        if (this.hasSDK() && this._sdk.getUpdateManager) {
            return this._sdk.getUpdateManager()
        }
        return null;
    }

    loadingComplete(obj: any) {

    }

    setLoadingProgress(obj: any) {

    }


    previewImage(obj: any) {
        if (!this.hasSDK() || !this._sdk.previewImage) {
            return;
        }
        this._sdk.previewImage(obj)
    }


    saveImage(obj: any) {
        if (!this.hasSDK() || !this._sdk.saveImageToPhotosAlbum) {
            return;
        }
        this._sdk.saveImageToPhotosAlbum(obj)
    }


    createCanvas() {
        if (this.hasSDK() && this._sdk.createCanvas) {
            return this._sdk.createCanvas()
        }
        return null;
    }

    hasSubpackage() {
        if (!this._sdk || !this._sdk.loadSubpackage) {
            return false;
        }
        return true;
    }

    request(param: any) {
        if (this._sdk) {
            this._sdk.request(param)
        }
    }
}










